package com.example.psychologicalappointmentsystem.Constants.websocket;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * ClassName WebSocketSessionRegistry
 * Description TODO 用户在线管理
 * Date 2025/2/14 16:27
 * Version 1.0
 */
@Component
public class WebSocketSessionRegistry {
    private final Map<Long, String> userSessionMap = new ConcurrentHashMap<>();

    public void registerSession(Long userId, String sessionId) {
        userSessionMap.put(userId, sessionId);
    }

    public void removeSession(Long userId) {
        userSessionMap.remove(userId);
    }

    public boolean isUserOnline(Long userId) {
        return userSessionMap.containsKey(userId);
    }
}
